package pat.basiclevel;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public interface ScoreRank {
    Student[] findMaxAndMinScore(List<Student> students);
}
class Student{
    private String name;
    private String id;
    private int score;

    public Student(String name, String id, int score){
        this.name = name;
        this.id = id;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }
}

class ScoreRankMain{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int studentNum = input.nextInt();
        input.nextLine();
        List<Student> students = new ArrayList<>();
        if(studentNum == 0){
            return;
        }
        for (int i = 0; i < studentNum; i++) {
            String[] line = input.nextLine().split(" ");

            Student student = new Student(line[0], line[1], Integer.parseInt(line[2]));
            students.add(student);
        }
        Student[] ans = new ScoreRankImpl1().findMaxAndMinScore(students);
        for(Student student : ans){
            System.out.println(student.getName() + " " + student.getId());
        }
    }
}
class ScoreRankImpl1 implements ScoreRank{

    @Override
    public Student[] findMaxAndMinScore(List<Student> students) {
        Student max = students.get(0);
        Student min = max;
        int size = students.size();
        for (int i = 1; i < size; i++) {
            Student curStudent = students.get(i);
            if(curStudent.getScore() > max.getScore()){
                max = curStudent;
            }
            if(curStudent.getScore() < min.getScore()){
                max = curStudent;
            }
        }
        return new Student[]{max,min};
    }
}

class ScoreRankImpl2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int studentNum = input.nextInt();
        if(studentNum == 0){
            return;
        }
        input.nextLine();
        String[][] students = new String[studentNum][3];
        for (int i = 0; i < studentNum; i++) {
            String[] lines = input.nextLine().split(" ");
            students[i] = lines;
        }

        int maxLine = 0, minLine = 0, maxScore = Integer.parseInt(students[0][2]), minScore = maxScore;
        for (int i = 1; i < studentNum; i++) {
            int score = Integer.parseInt(students[i][2]);
            if(score < minScore){
                minLine = i;
                minScore = score;
            }
            if(score > maxScore){
                maxLine = i;
                maxScore = score;
            }
        }
        System.out.println(students[maxLine][0] + " " + students[maxLine][1]);

        System.out.println(students[minLine][0] + " " + students[minLine][1]);
    }
}